#!/bin/sh

cd $(dirname $0)
cd ../..

# If you want to allow linter errors set this variable to true.
eslint=$(git config hooks.ignore-eslint)

echo "Linting Meteor tool code..."

./scripts/admin/eslint/eslint.sh modified
linter_exit_code=$?

if [ "$eslint" != "true" ] && [ $linter_exit_code != 0 ]
then
  echo "Linter errors detected in pre-commit hook."
  echo 
  echo "Run the linter with ./scripts/admin/eslint/eslint.sh"
  echo
  echo "If you know what you are doing you can disable this"
  echo "check using:"
  echo
  echo "  git config hooks.ignore-eslint true"
  echo
  exit 1
fi
